package cn.edu.nsmc.modules.sys.service.impl;

import cn.edu.nsmc.common.utils.R;
import cn.edu.nsmc.modules.sys.dao.SysRepairmanValuationDao;
import cn.edu.nsmc.modules.sys.entity.SysRepairmanValuationEntity;
import cn.edu.nsmc.modules.sys.form.RepairmanValuationList;
import cn.edu.nsmc.modules.sys.form.req.ReqRepairmanValuationForm;
import cn.edu.nsmc.modules.sys.service.SysRepairmanValuationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author ZY
 * @Date 2024/2/29 16:41
 */
@Service("sysRepairmanValuationService")
public class SysRepairmanValuationServiceImpl  extends ServiceImpl<SysRepairmanValuationDao, SysRepairmanValuationEntity> implements SysRepairmanValuationService {
    @Resource
    private SysRepairmanValuationDao sysRepairmanValuationDao;
    @Override
    public R addRepairmanValuation(SysRepairmanValuationEntity sysRepairmanValuationEntity) {
        int i = sysRepairmanValuationDao.insert(sysRepairmanValuationEntity);
        return i == 1 ? R.ok("添加成功") : R.error("添加失败");
    }

    @Override
    public R deleteRepairmanByIds(String[] ids) {
        for (String _id : ids) {
            Long aId = Long.valueOf(_id);
            Integer i = sysRepairmanValuationDao.deleteById(aId);
            if (i == 0) {
                return R.error("删除失败");
            }
        }
        return R.ok("删除成功");
    }

    @Override
    public R updateRepairmanValuation(SysRepairmanValuationEntity sysRepairmanValuationEntity) {
        int i = sysRepairmanValuationDao.updateRepairmanValuation(sysRepairmanValuationEntity);
        return i == 1 ? R.ok("修改成功") : R.error("修改失败");
    }

    @Override
    public R getRepairmanValuationList(RepairmanValuationList repairmanValuationList) {
//        if (repairmanValuationList.getRepairmanName()!=null&& !repairmanValuationList.getRepairmanName().equals("")){
//            repairmanValuationList.setRepairmanId();
//        }
//        if (repairmanValuationList.getValuatorName()!=null&& !repairmanValuationList.getValuatorName().equals("")){
//            repairmanValuationList.setValuatorId();
//        }
        repairmanValuationList.setPage((repairmanValuationList.getPage() - 1) * repairmanValuationList.getSize());
        List<ReqRepairmanValuationForm> list = sysRepairmanValuationDao.getRepairmanList(repairmanValuationList);
        Integer total = sysRepairmanValuationDao.getRepairmanListNumber(repairmanValuationList);
        R r =  R.page("查询成功", list, total);
        return r;
    }
}
